#!/bin/bash
limit_in_bytes=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes)
# If not default limit_in_bytes in cgroup
if [ "$limit_in_bytes" -ne "9223372036854771712" ]
then
    limit_in_megabytes=$(expr $limit_in_bytes \/ 1048576)
    echo limit_in_megabytes=$limit_in_megabytes
    heap_size=$(expr $limit_in_megabytes - $reserved_megabytes)
    echo reserved_megabytes=$reserved_megabytes
    export JAVA_OPTS="-Xmx${heap_size}m $JAVA_OPTS"
    echo JAVA_OPTS=$JAVA_OPTS
fi
exec java -Djava.security.egd=file:/dev/./urandom ${JAVA_OPTS} -jar /app.jar